﻿Imports DotNetNuke.Entities.Modules

Namespace DnnSun.Modules.Recommendation
    Partial Public Class ModuleOptions
        Inherits ModuleSettingsBase

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If (Not Page.IsPostBack) Then
                LoadSettings()
            End If
        End Sub

        Public Overrides Sub LoadSettings()
            Try
                If (Not ModuleSettings.Item("ShowMessageBox") Is Nothing) Then
                    Me.chkShowMessageBox.Checked = Convert.ToBoolean(ModuleSettings.Item("ShowMessageBox"))
                End If

                If (Not String.IsNullOrEmpty(ModuleSettings.Item("EmailTemplate"))) Then
                    Me.txtMessageTemplate.Text = ModuleSettings.Item("EmailTemplate").ToString
                Else
                    Me.txtMessageTemplate.Text = Localization.GetString("DefaultTemplate", LocalResourceFile)
                End If

                If (Not String.IsNullOrEmpty(ModuleSettings.Item("CustomMessage"))) Then
                    Me.txtCustomMessage.Text = ModuleSettings.Item("CustomMessage").ToString
                End If
            Catch exc As Exception
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Public Overrides Sub UpdateSettings()
            Try
                Dim controller As New ModuleController
                controller.UpdateModuleSetting(ModuleId, "ShowMessageBox", IIf(Me.chkShowMessageBox.Checked, "True", "False"))
                controller.UpdateModuleSetting(ModuleId, "EmailTemplate", Me.txtMessageTemplate.Text)
                controller.UpdateModuleSetting(ModuleId, "CustomMessage", Me.txtCustomMessage.Text)
            Catch exc As Exception
                'Exceptions.ProcessModuleLoadException(DirectCast(Me, PortalModuleBase), exception)
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub


        Private Sub cmdUpdateOptions_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdateOptions.Click
            Try
                UpdateSettings()

                Response.Redirect(NavigateURL(), True)
            Catch exc As Exception 'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Private Sub cmdCancelOptions_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdCancelOptions.Click
            Try
                Response.Redirect(NavigateURL(), True)
            Catch exc As Exception 'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Private Sub cmdReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdReset.Click
            If (Not String.IsNullOrEmpty(ModuleSettings.Item("EmailTemplate"))) Then
                Me.txtMessageTemplate.Text = ModuleSettings.Item("EmailTemplate").ToString
            Else
                Me.txtMessageTemplate.Text = Localization.GetString("DefaultTemplate", LocalResourceFile)
            End If
        End Sub
    End Class
End Namespace

